var window = "", imgPath = "/sdcard/1.jpg"
const permissionsScreenshot = screenshotRequest()
if (!requestScreenCapture()) {
    toast("请求截图失败");
    exit();
}
permissionsScreenshot && permissionsScreenshot.interrupt()
sleep(2000)
aaa()

function aaa() {
    img = captureScreen();
    // var 原图 = images.clip(img, 129, 924, 800, 540);
    var 二值化图 = images.threshold(img, 150, 255, "BINARY")
    newImg = images.inRange(二值化图, "#000000", "#AAAAAA")
    images.save(newImg, "/sdcard/1.jpg", "jpg", 100);
    media.scanFile("/sdcard/1.jpg")
    app.viewFile("/sdcard/1.jpg");
    sleep(1000)
    二值化图.recycle();
    getImgFingerprint(newImg)
}

function getImgFingerprint(img) {
    let x, y, nums, value0, value1
    for (x = 300; x < 920; x++) {
        nums = 0
        for (y = 914; y < 1376; y++) {
            value0 = (Number(images.pixel(img, x - 1, y)) != -1 ? 0 : 1)
            value1 = (Number(images.pixel(img, x, y)) != -1 ? 0 : 1)
            if (value0 == 0 && value1 == 1 && ++nums > 25) {
                log("竖线横坐标" + x)
                break
            }
        }
    }
    img.recycle();
}
/* 截图权限 */
function screenshotRequest() {
    console.log("开启截图权限")
    return threads.start(function () {
        while (true)
            if (text("立即开始").exists()) {
                sleep(500)
                Bounds(text("立即开始").findOne())
            } else if (text("允许").exists()) {
                sleep(500)
                Bounds(text("允许").findOne())
            }
    })
}

/**
 * 点击
 * @param {控件} obj
 */
function Bounds(obj) {
    try {
        obs = obj.bounds();
        click((Math.abs(obs.left) + Math.abs(obs.right)) / 2, (Math.abs(obs.top) + Math.abs(obs.bottom)) / 2);
    } catch (e) {
        Bounds(obj);
    }
}